// 引入axios组件
import axios from 'axios';
import qs from 'qs'; // 处理数据  qs.stringify(params)
import { checkRule } from '@/assets/js/public';
// 引入公共js文件
export default {
  data() {
    return {
      title: '', // 面包屑标题
      authlist: [], // 选中的权限数组
      categorylist: [], // 规则数组
      authid: '', // 角色id
      buttonProps: {
        type: 'ghost',
        size: 'small',
      },
      //= =========================以下是模态框相关
    };
  },
  created() {
    this.$Spin.show();
    setTimeout(() => {
      this.$Spin.hide();
    }, 500);
    const userid = this.$route.query.roleid;
    if (userid) {
      const self = this;
      axios({
        method: 'post',
        url: '/admin/admin/authDisbute',
        data: { authid: userid },
      })
        .then((response) => {
          checkRule(response, self); // 检查是否有权限
          self.categorylist = response.data.auth_list;
          self.authlist = response.data.rule_arr;
          self.authid = response.data.authid;
        })
        .catch((response) => {});
    } else {
      // self.$Message.error("缺少参数");
    }
  },

  methods: {
    editCategory() {
      // console.log(this.authlist);
      const self = this; // 将this对象附到一个不可更改的变量中~
      this.modal1 = true; // 模态框显示开关，true显示   false不显示
      axios({
        method: 'post',
        url: '/admin/admin/authUpdate',
        data: { authid: self.authid, authlist: self.authlist },
      })
        .then((response) => {
          checkRule(response, self); // 检查是否有权限

          if (response.data.code == 1) {
            self.$Message.success('操作成功');
          }
        })
        .catch((response) => {
          // self.$Message.error("请求失败");
        });
    },
  },
};
